package com.example.web03homework.dao;

import com.example.web03homework.Mapper.BookMapper;
import com.example.web03homework.pojo.Book;
import com.example.web03homework.pojo.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class BookDao {
    
    @Autowired
    private BookMapper bookMapper;
    
    public Book getById(Integer id) {
        return bookMapper.getById(id);
    }
    
    public List<Book> getByCondition(String keyword, Integer categoryId) {
        return bookMapper.getByCondition(keyword, categoryId);
    }
    
    public void insert(Book book) {
        bookMapper.insert(book);
    }
    
    public void update(Book book) {
        bookMapper.update(book);
    }
    
    public void updateStatus(Integer id, Integer status) {
        bookMapper.updateStatus(id, status);
    }
    
    public void deleteById(Integer id) {
        bookMapper.deleteById(id);
    }
    
    public void deleteByIds(List<Integer> ids) {
        bookMapper.deleteByIds(ids);
    }
    
    public List<Category> getAllCategories() {
        return bookMapper.getAllCategories();
    }
    
    public int countBooksByCategoryId(Integer categoryId) {
        return bookMapper.countBooksByCategoryId(categoryId);
    }
}
